<template>
    <div class="sku_dialog">
        <el-form enctype="multipart/form-data" id="addsku_form">
            <el-form-item label="选择图片" label-width="120px">
                <input type="file" name="sku_img" id="add_img">
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer right" style="text-align:right">
            <el-button @click="dialog_show = false" size="small">取 消</el-button>
            <el-button type="primary" @click="add_sku()" size="small">确 定</el-button>
        </div>
    </div>
</template>
<script>
import g from '../../components/global.js'
export default {
  props: ['message'],
  data() {
    return {}
  },
  methods: {
    add_sku() {
      var _this = this
      if($("#add_img").val() == ''){
          _this.$message.error('sku图片不能为空')
          return;
      }
      var formData = new FormData($('#addsku_form')[0])
      formData.append('product_id', _this.message)
      $.ajax({
        url: g.res_url + '/api/v1/add_sku',
        data: formData,
        type: 'POST',
        data: formData,
        async: false,
        cache: false,
        contentType: false,
        processData: false,
        success: function(data) {
          if (data == 'success') {
            _this.$message.success('操作成功')
          } else {
            _this.$message.error('操作失败')
          }
        },
        error: function() {
          _this.$message.error('网络繁忙')
        }
      })
      this.$emit('sku_success', 'success')
    }
  }
}
</script>

